package com.wry.wry_test.model.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: wangrongyi
 * @Date: 2024/10/8 10:27
 * @Description: 文件类型枚举
 */
@AllArgsConstructor
@Getter
public enum FileTypeEnum {


    JPG("FFD8FF", "jpg"),
    PNG("89504E47", "png"),
    GIF("47494638", "gif"),
    TIFF("49492A00", "tiff"),
    BMP("424D", "bmp"),
    DWG("41433130", "dwg"),
    PSD("38425053", "psd"),
    RTF("7B5C727466", "rtf"),
    XML("3C3F786D6C", "xml"),
    HTML("68746D6C3E", "html"),
    EML("44656C69766572792D646174653A", "eml"),
    DBX("CFAD12FEC5FD746F", "dbx"),
    PST("2142444E", "pst"),
    XLS_DOC("D0CF11E0", "xls/doc"),
    XLSX_DOCX("504B0304", "xlsx/docx"),
    MDB("5374616E64617264204A", "mdb"),
    WPD("FF575043", "wpd"),
    EPS("252150532D41646F6265", "eps"),
    PDF("255044462D312E", "pdf"),
    QDF("AC9EBD8F", "qdf"),
    PWL("E3828596", "pwl"),
    ZIP("504B0304", "zip"),
    RAR("52617221", "rar"),
    WAV("57415645", "wav"),
    AVI("41564920", "avi"),
    RAM("2E7261FD", "ram"),
    RM("2E524D46", "rm"),
    MPG("000001BA", "mpg"),
    MOV("6D6F6F76", "mov"),
    ASF("3026B2758E66CF11", "asf"),
    MID("4D546864", "mid"),
    MP4("00000020667479706D70", "mp4"),
    MP3("49443303000000002176", "mp3"),
    FLV("464C5601050000000900", "flv"),
    SQL("494E5345525420494E54", "sql"),
    CSV("4D534346", "csv"),
    JSP("3C2540207061676520", "jsp"),
    JAVA("7061636B61676520", "java"),
    CLASS("CAFEBABE000000", "class"),
    JAR("504B03040A000000", "jar"),
    MF("4D616E69666573742D56", "mf"),
    EXE("4D5A9000030000000400", "exe"),
    CHM("49545346030000006000", "chm"),
    MDF("4554", "mdf"),
    ISO("434450", "iso"),
    TXT("6C6F67346A2E7265", "txt");

    public static int  MAX_HEAD_LENGTH = 0;


    static {
        // 初始化数据
        for (FileTypeEnum fileTypeEnum : FileTypeEnum.values()) {

            MAX_HEAD_LENGTH = Math.max(MAX_HEAD_LENGTH, fileTypeEnum.hexCode.length() / 2);

        }

    }

    private final String hexCode;
    private final String type;

    public static FileTypeEnum getByHexCode(String hexCode) {
        for (FileTypeEnum fileTypeEnum : FileTypeEnum.values()) {
            if (hexCode.startsWith(fileTypeEnum.hexCode)) {
                return fileTypeEnum;
            }
        }
        return null;
    }
}
